using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace LS.GameKit
{
    [RequireComponent(typeof(Trigger3DBehaviour))]
    public class Platform3DBehaviour : PlatformBehaviour
    {
        [SerializeField]
        private Trigger3DBehaviour m_Trigger;

        protected override void Awake()
        {
            base.Awake();
            if (m_Trigger == null)
                m_Trigger = GetComponent<Trigger3DBehaviour>();
        }

        public override void MoveCaughtObjects(Vector3 delta)
        {
            if (m_Trigger != null)
            {
                if (m_CaughtType == MoveType.AllCaughtColliders)
                {
                    var results = m_Trigger.GetAllInsideColliders();
                    for (int i = 0; i < results.Length; i++)
                    {
                        results[i].transform.Translate(delta, Space.World);
                    }
                }
                else if (m_CaughtType == MoveType.PhysicsBehavioursOnly)
                {
                    var results = m_Trigger.GetAllPhysicsResults();
                    for (int i = 0; i < results.Length; i++)
                    {
                        var physicsBehaviour = results[i].TargetBehaviour;
                        physicsBehaviour.Translate(delta);
                    }
                }
            }
        }

        public virtual void Reset()
        {
            m_Trigger = GetComponent<Trigger3DBehaviour>();
        }
    }
}
